MAKE = mingw32-make
CC = gcc
export CC

PROJECT = zlog
WORKDIR = $(shell echo %cd%)
SRCDIR = $(WORKDIR)\src
DLLDIR = $(WORKDIR)\dll
LIBDIR = $(WORKDIR)\lib
OUTDIR = $(WORKDIR)\out
OBJDIR = $(OUTDIR)\obj
export OBJDIR

BUILDLOG = $(OUTDIR)\build.log
DLLFILE = $(OUTDIR)\lib$(PROJECT).dll
LIBFILE = $(OUTDIR)\lib$(PROJECT).lib

new:pre compile link strip logtime

pre:
	@ echo prepare environment ...
	@ if not exist $(strip $(OUTDIR)) \
		@ mkdir $(strip $(OUTDIR))
	@ if exist $(strip $(BUILDLOG)) \
		@ del /f  $(strip $(BUILDLOG))
	@ echo environment ok

compile:
	@ echo make $(SRCDIR)
	@ $(MAKE) -C $(SRCDIR)
	
link:
	@ echo link ...
	@ $(CC) -shared -o $(DLLFILE) $(OBJDIR)\*.o -static-libgcc -Wl,-Bstatic -lpthread -Wl,-Bdynamic -lwsock32 -Wl,--out-implib,$(LIBFILE) 2>$(BUILDLOG)
	@ echo link ok

strip:
	@ echo strip...
	@ strip $(DLLFILE)
	@ strip -g -S -d --strip-debug --strip-unneeded $(LIBFILE)
	@ echo strip ok
	
clean:
	@ echo cleaning ...
	@ if exist $(strip $(OUTDIR)) \
		@ rmdir /s /q $(strip $(OUTDIR))
	@ echo clean ok

logtime:
	@ echo buildtime: %date:~0,10% %time:~0,8%